namespace FileTransfer.Client.Utils;

public static class StringFormat
{
    private static readonly string[] SizeSuffixes =
    {
        "bytes",
        "KB",
        "MB",
        "GB",
        "TB",
        "PB",
        "EB",
        "ZB",
        "YB",
    };

    public static string FormatSize(long bytes)
    {
        if (bytes == 0)
            return "0 bytes";

        var magnitude = (int)Math.Log(bytes, 1024);
        var adjustedSize = (decimal)bytes / (1L << (magnitude * 10));

        return string.Format("{0:n2} {1}", adjustedSize, SizeSuffixes[magnitude]);
    }
}
